﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using secondhand.L2busslogic;
using secondhand.L1database;
using secondhand.L3object;
using System.IO;

namespace secondhand.L4view.yonghu
{
    public partial class yonghu_receive_goods : System.Web.UI.Page
    {
        public static string salerName;
        protected void Page_Load(object sender, EventArgs e)
        {
            bookOB mydd = new bookOB();
            mydd = bookBL.Getwordsingle1(Session["login"].ToString(),(Session["receive_goodsName"].ToString()));
            Label6.Text = mydd.book_name;
            Label7.Text = mydd.book_type;
            Label8.Text = mydd.book_price;
            Label9.Text = mydd.book_describe;
            Image1.ImageUrl = mydd.book_picture;
            salerName = mydd.saler_name;
            if (mydd.receive_goods == "1")
            {
                Button1.Visible = false;
                Button1.Enabled = false;
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            userOB mydd = new userOB();
            mydd = userBL.Getwordsingle(Session["login"].ToString());
            int ss = (int)Convert.ToSingle(mydd.freeze_count) - (int)Convert.ToSingle(Label8.Text);
            mydd.freeze_count = ss.ToString();
            int y = (int)Convert.ToSingle(mydd.user_count) - (int)Convert.ToSingle(Label8.Text);
            mydd.user_count = y.ToString();
            int bb = (int)Convert.ToSingle(mydd.user_count) - ss;
            mydd.usable_count = bb.ToString();
            salerOB myword = new salerOB();
            myword = salerBL.Getwordsingle(salerName);
            int m = (int)Convert.ToSingle(myword.saler_count) + (int)Convert.ToSingle(Label8.Text);
            myword.saler_count = m.ToString();
            if (userBL.Savemark(mydd))
            {
                if (salerBL.Savemark(myword))
                {
                    bookOB x = new bookOB();
                    x = bookBL.Getwordsingle(Label6.Text);
                    x.receive_goods = "1";
                    if (bookBL.Savemark(x))
                    {
                        Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('确认收货成功!');{location.href='yonghu_buy_list.aspx'}</script>");

                        return;
                    }
                    Button1.Visible = false;
                    Button1.Enabled = false;
                    return;
                }

            }
        }
    }
}